﻿<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub Page_Load()
        Dim ConnectionString As String = ConfigurationSettings.AppSettings("strcnn")
        Dim strsql As String
        Dim myConnection As New OleDbConnection(ConnectionString)
        Dim cnn as New OleDbConnection(ConnectionString)
        Dim myCommand as New OleDbCommand
        Dim cmd as New OleDbCommand
        Dim myDataReader as OleDbDataReader
        Dim dr as OleDbDataReader
        myConnection.Open()
        cnn.Open()
        myCommand.Connection = myConnection
        cmd.Connection = cnn
    
        select(Request.Form("acao"))
        case "excluir":
            Dim primeiro as Boolean = true
            for each i as String in Request.Form
                if i <> "acao" and i <> "RazaoSocial" and i <> "Cidade" and i <> "Vendedor" then
                    if primeiro then
                        strsql = "delete * from cliente where ID=" & i
                        primeiro = false
                    else
                        strsql = strsql & " or ID=" & i
                    End if
                End if
            next
            if strsql <> "" then
                myCommand.CommandText = strsql
                myCommand.ExecuteNonQuery()
            End if
        case "inserir":
            strsql = "INSERT INTO Cliente ( IDVendedor, IDTransportadora, RazaoSocial, Endereco, Bairro, CEP, Cidade, Estado, Telefone, Fax, Email, CNPJ, InscricaoEstadual, Contato, Observacao, CodigoJolitex, EnderecoEntrega, BairroEntrega, CNPJEntrega, TelefoneEntrega, FaxEntrega, InscricaoEstadualEntrega, EnderecoCobranca, BairroCobranca, CEPCobranca, CidadeCobranca, EstadoCobranca, CNPJCobranca, InscricaoEstadualCobranca, TelefoneCobranca, FaxCobranca, Regiao, cepentrega, cidadeentrega, estadoentrega ) values (" & Request.Form("IDVendedor") & ", " & Request.Form("IDTransportadora") & ", '" & Request.Form("RazaoSocial") & "', '" & Request.Form("Endereco") & "', '" & Request.Form("Bairro") & "', '" & Request.Form("CEP") & "', '" & Request.Form("Cidade") & "', '" & Request.Form("Estado") & "', '" & Request.Form("Telefone") & "', '" & Request.Form("Fax") & "', '" & Request.Form("Email") & "', '" & Request.Form("CNPJ") & "', '" & Request.Form("InscricaoEstadual") & "', '" & Request.Form("Contato") & "', '" & Request.Form("Observacao") & "', '" & Request.Form("CodigoJolitex") & "', '" & Request.Form("EnderecoEntrega") & "', '" & Request.Form("BairroEntrega") & "', '" & Request.Form("CNPJEntrega") & "', '" & Request.Form("TelefoneEntrega") & "', '" & Request.Form("FaxEntrega") & "', '" & Request.Form("InscricaoEstadualEntrega") & "', '" & Request.Form("EnderecoCobranca") & "', '" & Request.Form("BairroCobranca") & "', '" & Request.Form("CEPCobranca") & "', '" & Request.Form("CidadeCobranca") & "', '" & Request.Form("EstadoCobranca") & "', '" & Request.Form("CNPJCobranca") & "', '" & Request.Form("InscricaoEstadualCobranca") & "', '" & Request.Form("TelefoneCobranca") & "', '" & Request.Form("FaxCobranca") & "', " & Request.Form("Regiao") & ", '" & Request.Form("cepentrega") & "', '" & Request.Form("cidadeentrega") & "', '" & Request.Form("estadoentrega") & "')"
            myCommand.CommandText = strsql
            myCommand.ExecuteNonQuery()
        case "alterar":
            strsql = "UPDATE Cliente SET Cliente.IDVendedor = " & Request.Form("IDVendedor") & ", Cliente.IDTransportadora = " & Request.Form("IDTransportadora") & ", Cliente.RazaoSocial = '" & Request.Form("RazaoSocial") & "', Cliente.Endereco = '" & Request.Form("Endereco") & "', Cliente.Bairro = '" & Request.Form("Bairro") & "', Cliente.CEP = '" & Request.Form("CEP") & "', Cliente.Cidade = '" & Request.Form("Cidade") & "', Cliente.Estado = '" & Request.Form("Estado") & "', Cliente.Telefone = '" & Request.Form("Telefone") & "', Cliente.Fax = '" & Request.Form("FAX") & "', Cliente.Email = '" & Request.Form("Email") & "', Cliente.CNPJ = '" & Request.Form("CNPJ") & "', Cliente.InscricaoEstadual = '" & Request.Form("InscricaoEstadual") & "', Cliente.Contato = '" & Request.Form("Contato") & "', Cliente.Observacao = '" & Request.Form("Observacao") & "', Cliente.CodigoJolitex = '" & Request.Form("CodigoJolitex") & "', Cliente.EnderecoEntrega = '" & Request.Form("EnderecoEntrega") & "', Cliente.BairroEntrega = '" & Request.Form("BairroEntrega") & "', Cliente.CNPJEntrega = '" & Request.Form("CNPJEntrega") & "', Cliente.TelefoneEntrega = '" & Request.Form("TelefoneEntrega") & "', Cliente.FaxEntrega = '" & Request.Form("FaxEntrega") & "', Cliente.InscricaoEstadualEntrega = '" & Request.Form("InscricaoEstadualEntrega") & "', Cliente.EnderecoCobranca = '" & Request.Form("EnderecoCobranca") & "', Cliente.BairroCobranca = '" & Request.Form("BairroCobranca") & "', Cliente.CEPCobranca = '" & Request.Form("CEPCobranca") & "', Cliente.CidadeCobranca = '" & Request.Form("CidadeCobranca") & "', Cliente.EstadoCobranca = '" & Request.Form("EstadoCobranca") & "', Cliente.CNPJCobranca = '" & Request.Form("CNPJCobranca") & "', Cliente.InscricaoEstadualCobranca = '" & Request.Form("InscricaoEstadualCobranca") & "', Cliente.TelefoneCobranca = '" & Request.Form("TelefoneCobranca") & "', Cliente.FaxCobranca = '" & Request.Form("FaxCobranca") & "', Cliente.Regiao = " & Request.Form("Regiao") & ", cliente.cepentrega = '" & Request.Form("cepentrega") & "', cliente.cidadeentrega = '" & Request.Form("cidadeentrega") & "', cliente.estadoentrega = '" & Request.Form("estadoentrega") & "' where id=" & Request.Form("id")
            myCommand.CommandText = strsql
            myCommand.ExecuteNonQuery()
        End select
    
        select(Request("acao"))
        case "exibir":
            strsql = "SELECT Cliente.*, Vendedor.ID, Vendedor.Nome, Transportadora.ID, Transportadora.RazaoSocial FROM Transportadora INNER JOIN (Vendedor INNER JOIN Cliente ON Vendedor.ID = Cliente.IDVendedor) ON Transportadora.ID = Cliente.IDTransportadora where Cliente.ID=" & Request.QueryString("id") & " order by Cliente.RazaoSocial asc"
            myCommand.CommandText = strsql
            myDataReader = myCommand.ExecuteReader()
            myDataReader.Read()
            Painel.Text = "<h3>Exibir:</h3><table border='0' cellspacing='0' cellpadding='4'>"
            Painel.Text = Painel.Text & "<tr><td>Razão social:</td><td>" & myDataReader("Cliente.RazaoSocial") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Vendedor:</td><td><a href='vendedor.aspx?acao=exibir&id=" & myDataReader("Vendedor.ID") & "'>" & myDataReader("Nome") & "</a></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Transportadora:</td><td><a href='transportadora.aspx?acao=exibir&id=" & myDataReader("Transportadora.ID") & "'>" & myDataReader("Transportadora.RazaoSocial") & "</a></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço:</td><td>" & myDataReader("Endereco") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro:</td><td>" & myDataReader("Bairro") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP:</td><td>" & myDataReader("CEP") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade:</td><td>" & myDataReader("Cidade") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado:</td><td>" & myDataReader("Estado") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone:</td><td>" & myDataReader("Telefone") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax:</td><td>" & myDataReader("Fax") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>E-mail:</td><td><a href='enviaremail.aspx?email=" & myDataReader("Email") & "&razaosocial=" & myDataReader("Cliente.RazaoSocial") & "'>" & myDataReader("Email") & "</a></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ:</td><td>" & myDataReader("CNPJ") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscrição estadual:</td><td>" & myDataReader("InscricaoEstadual") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Contato:</td><td>" & myDataReader("Contato") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Observação:</td><td>" & myDataReader("Observacao") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Código Jolitex:</td><td>" & myDataReader("CodigoJolitex") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Região:</td><td>" & myDataReader("Regiao") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço entrega:</td><td>" & myDataReader("EnderecoEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro entrega:</td><td>" & myDataReader("BairroEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP entrega:</td><td>" & myDataReader("CEPEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade entrega:</td><td>" & myDataReader("CidadeEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado entrega:</td><td>" & myDataReader("EstadoEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ Entrega:</td><td>" & myDataReader("CNPJEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone entrega:</td><td>" & myDataReader("TelefoneEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax entrega:</td><td>" & myDataReader("FaxEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Isncr. est. entrega:</td><td>" & myDataReader("InscricaoEstadualEntrega") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço cobrança:</td><td>" & myDataReader("EnderecoCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro cobrança:</td><td>" & myDataReader("BairroCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP cobrança:</td><td>" & myDataReader("CEPCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade cobrança:</td><td>" & myDataReader("CidadeCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado cobrança:</td><td>" & myDataReader("EstadoCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ cobrança:</td><td>" & myDataReader("CNPJCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscr. est. cobrança:</td><td>" & myDataReader("InscricaoEstadualCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone cobrança:</td><td>" & myDataReader("TelefoneCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax cobrança:</td><td>" & myDataReader("FaxCobranca") & "</td></tr>"
            Painel.Text = Painel.Text & "<tr><td><form method='post' action='cliente.aspx'><input type='hidden' name='acao' value='formalterar'><input type='hidden' name='id' value='" & Request.QueryString("id") & "'><input type='submit' value='Alterar'></form></td>"
            Painel.Text = Painel.Text & "<td><form action='cliente.aspx'><input type='submit' value='Cancelar'></form></td></tr>"
            Painel.Text = Painel.Text & "</table>"
            myDataReader.Close()
        case "formalterar":
            strsql = "select * from cliente where id=" & Request.Form("id")
            myCommand.CommandText = strsql
            myDataReader = myCommand.ExecuteReader()
            myDataReader.Read()
            Painel.Text = "<h3>Alterar:</h3><form method='post' action='cliente.aspx'><input type='hidden' name='acao' value='alterar'><input type='hidden' name='id' value='" & myDataReader("ID") & "'><table border='0' cellspacing='0' cellpadding='4'>"
            Painel.Text = Painel.Text & "<tr><td>Razão social:</td><td><input name='RazaoSocial' value='" & myDataReader("RazaoSocial") & "'></td></tr>"
            cmd.CommandText = "select id, nome from vendedor order by nome asc"
            dr = cmd.ExecuteReader()
            Painel.Text = Painel.Text & "<tr><td>Vendedor:</td><td><select name='IDVendedor'>"
                while dr.Read()
                    Painel.Text = Painel.Text & "<option value='" & dr("id") & "'" & iif(dr("id")=myDataReader("idvendedor"), "selected", "") & ">" & dr("nome") & "</option>"
                End while
            Painel.Text = Painel.Text & "</select></td></tr>"
            dr.Close()
            cmd.CommandText = "select id, razaosocial from transportadora order by razaosocial asc"
            dr = cmd.ExecuteReader()
            Painel.Text = Painel.Text & "<tr><td>Transportadora:</td><td><select name='IDTransportadora'>"
                while dr.Read()
                    Painel.Text = Painel.Text & "<option value='" & dr("id") & "'" & iif(dr("id")=myDataReader("idtransportadora"), "selected", "") & ">" & dr("razaosocial") & "</option>"
                End while
            Painel.Text = Painel.Text & "</select></td></tr>"
            dr.Close()
            Painel.Text = Painel.Text & "<tr><td>Endereço:</td><td><input name='Endereco' value='" & myDataReader("Endereco") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro:</td><td><input name='Bairro' value='" & myDataReader("Bairro") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP:</td><td><input name='CEP' value='" & myDataReader("CEP") & "' maxlength='10'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade:</td><td><input name='Cidade' value='" & myDataReader("Cidade") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado:</td><td><input name='Estado' value='" & myDataReader("Estado") & "' maxlength='2'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone:</td><td><input name='Telefone' value='" & myDataReader("Telefone") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax:</td><td><input name='Fax' value='" & myDataReader("Fax") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>E-mail:</td><td><input name='Email' value='" & myDataReader("Email") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ:</td><td><input name='CNPJ' value='" & myDataReader("CNPJ") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscrição estadual:</td><td><input name='InscricaoEstadual' value='" & myDataReader("InscricaoEstadual") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Contato:</td><td><input name='Contato' value='" & myDataReader("Contato") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Observação:</td><td><textarea name='Observacao' rows='5' cols='30'>" & myDataReader("Observacao") & "</textarea></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Código Jolitex:</td><td><input name='CodigoJolitex' value='" & myDataReader("CodigoJolitex") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Região:</td><td><input name='Regiao' value='" & myDataReader("Regiao") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço entrega:</td><td><input name='EnderecoEntrega' value='" & myDataReader("EnderecoEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro entrega:</td><td><input name='BairroEntrega' value='" & myDataReader("BairroEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ entrega:</td><td><input name='CNPJEntrega' value='" & myDataReader("CNPJEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone entrega:</td><td><input name='TelefoneEntrega' value='" & myDataReader("TelefoneEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax entrega:</td><td><input name='FaxEntrega' value='" & myDataReader("FaxEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP entrega:</td><td><input name='CEPEntrega' value='" & myDataReader("CEPEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade entrega:</td><td><input name='CidadeEntrega' value='" & myDataReader("CidadeEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado entrega:</td><td><input name='EstadoEntrega' value='" & myDataReader("EstadoEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscr. est. entrega:</td><td><input name='InscricaoEstadualEntrega' value='" & myDataReader("InscricaoEstadualEntrega") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço cobrança:</td><td><input name='EnderecoCobranca' value='" & myDataReader("EnderecoCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro cobrança:</td><td><input name='BairroCobranca' value='" & myDataReader("BairroCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP cobrança:</td><td><input name='CEPCobranca' value='" & myDataReader("CEPCobranca") & "' maxlength='10'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade cobrança:</td><td><input name='CidadeCobranca' value='" & myDataReader("CidadeCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado cobrança:</td><td><input name='EstadoCobranca' value='" & myDataReader("EstadoCobranca") & "' maxlength='2'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ cobrança:</td><td><input name='CNPJCobranca' value='" & myDataReader("CNPJCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscr. est. cobrança:</td><td><input name='InscricaoEstadualCobranca' value='" & myDataReader("InscricaoEstadualCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone cobrança:</td><td><input name='TelefoneCobranca' value='" & myDataReader("TelefoneCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax cobrança:</td><td><input name='FaxCobranca' value='" & myDataReader("FaxCobranca") & "'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td><input type='submit' value='Alterar'></td><td><input type='reset' value='Limpar'></td></tr>"
            Painel.Text = Painel.Text & "</table></form>"
            myDataReader.Close()
        case else:
            Painel.Text = "<h3>Inserir:</h3><form method='post' action='cliente.aspx'><input type='hidden' name='acao' value='inserir'><table border='0' cellspacing='0' cellpadding='4'>"
            Painel.Text = Painel.Text & "<tr><td>Razão social:</td><td><input name='RazaoSocial'></td></tr>"
            cmd.CommandText = "select id, nome from vendedor order by nome asc"
            dr = cmd.ExecuteReader()
            Painel.Text = Painel.Text & "<tr><td>Vendedor:</td><td><select name='IDVendedor'>"
                while dr.Read()
                    Painel.Text = Painel.Text & "<option value='" & dr("id") & "'>" & dr("nome") & "</option>"
                End while
            Painel.Text = Painel.Text & "</select></td></tr>"
            dr.Close()
            cmd.CommandText = "select id, razaosocial from transportadora order by razaosocial asc"
            dr = cmd.ExecuteReader()
            Painel.Text = Painel.Text & "<tr><td>Transportadora:</td><td><select name='IDTransportadora'>"
                while dr.Read()
                    Painel.Text = Painel.Text & "<option value='" & dr("id") & "'>" & dr("razaosocial") & "</option>"
                End while
            Painel.Text = Painel.Text & "</select></td></tr>"
            dr.Close()
            Painel.Text = Painel.Text & "<tr><td>Endereço:</td><td><input name='Endereco'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro:</td><td><input name='Bairro'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP:</td><td><input name='CEP' maxlength='10'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade:</td><td><input name='Cidade'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado:</td><td><input name='Estado' maxlength='2'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone:</td><td><input name='Telefone'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax:</td><td><input name='Fax'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>E-mail:</td><td><input name='Email'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ:</td><td><input name='CNPJ'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscrição estadual:</td><td><input name='InscricaoEstadual'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Contato:</td><td><input name='Contato'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Observação:</td><td><textarea name='Observacao' rows='5' cols='30'></textarea></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Código Jolitex:</td><td><input name='CodigoJolitex'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Região:</td><td><input name='Regiao'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço entrega:</td><td><input name='EnderecoEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro entrega:</td><td><input name='BairroEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ entrega:</td><td><input name='CNPJEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP entrega:</td><td><input name='CEPentrega' maxlength='10'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade entrega:</td><td><input name='CidadeEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado entrega:</td><td><input name='EstadoEntrega' maxlength='2'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone entrega:</td><td><input name='TelefoneEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax entrega:</td><td><input name='FaxEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscr. est. entrega:</td><td><input name='InscricaoEstadualEntrega'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Endereço cobrança:</td><td><input name='EnderecoCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Bairro cobrança:</td><td><input name='BairroCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CEP cobrança:</td><td><input name='CEPCobranca' maxlength='10'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Cidade cobrança:</td><td><input name='CidadeCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Estado cobrança:</td><td><input name='EstadoCobranca' maxlength='2'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>CNPJ cobrança:</td><td><input name='CNPJCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Inscr. est. cobrança:</td><td><input name='InscricaoEstadualCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Telefone cobrança:</td><td><input name='TelefoneCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td>Fax cobrança:</td><td><input name='FaxCobranca'></td></tr>"
            Painel.Text = Painel.Text & "<tr><td><input type='submit' value='Inserir'></td><td><input type='reset' value='Limpar'></td></tr>"
            Painel.Text = Painel.Text & "</table></form>"
        End Select
    
        Busca.Text = "<table width='100%' border='0' cellspacing='2' cellpadding='2'><tr bgcolor='#000080'><td><font color='#FFFFFF'><b>Razão Social</b></font></td><td><font color='#FFFFFF'><b>Cidade</b></font></td><td><font color='#FFFFFF'><b>Telefone</b></font></td><td><font color='#FFFFFF'><b>Fax</b></font></td><td></td></tr>"
        strsql = ""
        Dim total as integer = 0
        if Request.Form("RazaoSocial") <> "" then strsql = "razaosocial like '%" & Request.Form("RazaoSocial") & "%'"
        if Request.Form("Cidade") <> "" then strsql = iif(strsql = "", "", strsql & " and ") & "cidade like '" & Request.Form("Cidade") & "%'"
        if Request.Form("Vendedor") <> "" then strsql = iif(strsql = "", "", strsql & " and ") & "idvendedor=" & Request.Form("Vendedor")
        if strsql <> "" then
            strsql = "select ID, RazaoSocial, Telefone, Fax, Cidade from cliente where " & strsql & " order by cidade, razaosocial asc"
            Dim cor as Boolean
           myCommand.CommandText = strsql
            myDataReader = myCommand.ExecuteReader()
           while myDataReader.Read()
            Busca.Text = Busca.Text & "<tr bgcolor='" & iif(cor, "#ADD8E6", "#E0FFFF") & "'><td><a href='cliente.aspx?acao=exibir&id=" & myDataReader("ID") & "'>" & myDataReader("RazaoSocial") & "</a></td><td>" & myDataReader("Cidade") & "</td><td>" & myDataReader("Telefone") & "</td><td>" & myDataReader("Fax") & "</td><td align='center'><input type='checkbox' name='" & myDataReader("ID") & "' value='true'></td></tr>"
               cor = not cor
            total = total + 1
           End while
            myDataReader.Close()
       End if
        Busca.Text = Busca.Text & "</table><hr><table border='0' cellspacing='2' cellpadding='2'>"
        Busca.Text = Busca.Text & "<tr><td>Total:</td><td>" & total & "</td></tr></table>"
    
        myCommand.CommandText = "select id, nome from vendedor order by nome asc"
        myDataReader = myCommand.ExecuteReader()
        Vendedor.Text = "<select name='Vendedor'><option value=''></option>"
        while myDataReader.Read()
            Vendedor.Text = Vendedor.Text & "<option value='" & myDataReader("id") & "'>" & myDataReader("nome") & "</option>"
        end while
	Vendedor.Text = Vendedor.Text + "</select>"
    
        myConnection.Close()
    End Sub
    
    Sub Imprimir_Click(sender As Object, e As EventArgs)
        Dim strsql As String = ""
        if Request.Form("RazaoSocial") <> "" then strsql = "cliente.razaosocial like %27%25" & Request.Form("RazaoSocial") & "%25%27"
        if Request.Form("Cidade") <> "" then strsql = iif(strsql = "", "", strsql & " and ") & "cliente.cidade like %27" & Request.Form("Cidade") & "%25%27"
        if Request.Form("Vendedor") <> "" then strsql = iif(strsql = "", "", strsql & " and ") & "cliente.idvendedor=" & Request.Form("Vendedor")
        strsql = "select cliente.codigojolitex, cliente.cidade, cliente.id, cliente.razaosocial, cliente.endereco, cliente.endereco, cliente.bairro, cliente.cnpj, cliente.inscricaoestadual, cliente.telefone, cliente.contato, vendedor.sigla from cliente, vendedor where vendedor.id=cliente.idvendedor " & iif(strsql="", "", "and " & strsql) & " order by cliente.cidade, cliente.razaosocial asc"
    
    '    Response.Write(strsql)
    '    Response.End
    
        Response.Redirect("clienteimprimir.aspx?strsql=" & strsql)
    End Sub

</script>
<html>
<head>
    <script language="vbscript">
    sub confirma()
        if msgbox("Confirmar exclusão?", vbYesNo) = vbYes then document.lista.submit()
    end sub
</script>
</head>
<body style="FONT-FAMILY: arial">
    <table bordercolor="navajowhite" cellspacing="0" cellpadding="2" width="950" align="center" bgcolor="floralwhite">
        <tbody>
            <tr>
                <td valign="center" align="middle" bgcolor="#ffdead" colspan="2">
                    <h2>Cliente 
                    </h2>
                </td>
            </tr>
            <tr>
                <td valign="top" width="550">
                    <table border="0">
                        <tbody>
                            <tr>
                                <td>
                                    <h3>Pesquisar: 
                                    </h3>
                                    <form method="post" runat="server">
                                        <table border="0">
                                            <tbody>
                                                <tr>
                                                    <td>
                                                        Razão social:</td>
                                                    <td>
                                                        <input name="RazaoSocial" /></td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Cidade:</td>
                                                    <td>
                                                        <input name="Cidade" /></td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Vendedor:</td>
                                                    <td>
                                                        <asp:Label id="Vendedor" runat="server"></asp:Label></td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <input type="submit" value="Pesquisar" /></td>
                                                    <td align="right">
                                                        <asp:Button id="Imprimir" onclick="Imprimir_Click" runat="server" Text="Imprimir"></asp:Button>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </form>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <form name="lista" method="post">
                                        <input type="hidden" value="excluir" name="acao" />
                                        <%="<input type='hidden' name='RazaoSocial' value='" & Request.Form("RazaoSocial") & "'>"%><asp:Label id="Busca" runat="server"></asp:Label>
                                        <br />
                                        <input onclick="vbscript:confirma()" type="button" value="Excluir" />
                                    </form>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
                <td valign="top" width="400">
                    <asp:Label id="Painel" runat="server"></asp:Label></td>
            </tr>
        </tbody>
    </table>
</body>
</html>
